#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <math.h>
#include "ds1338c.h"
#include "encode.h"

#define BCD_TO_DEC(val) (((val)&15) + ((val)>>4)*10)
#define DEC_TO_BCD(val)	((((val)/10)<<4) + (val)%10)

int main()
{
	int dev;
	ds_rtc_time get_time;

	#ifdef HI3511
	dev = open("/dev/misc/ds1338", O_RDONLY);
	#else
	dev = open("/dev/ds1338", O_RDONLY);
	#endif
	if (dev <= 0) {
		printf("ds1338 device open fail\n");
		exit(0);
	}

	while (1) {
		ioctl(dev, DS1338_RTC_GET_TIME, &get_time);	// get time

		printf("20%d 年 %d 月 %d 日 %d:%d:%d\n", get_time.year, 
									get_time.month,get_time.day,get_time.hour,get_time.minute,get_time.second);
		sleep(1);
	}

	close(dev);

	return 0;
}
